package www.openteam.com.model.qualityCntrl;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.IQCCust00;
import www.openteam.com.bean.IQCMsg00;
import www.openteam.com.bean.IQCSamplePlan;

/**
 * Created by Administrator on 2018/1/31 0031.
 */

public class IQCModel extends BaseModel {

    public void findMsg00( String code,final IQCModel.Msg00Listener listener){
        httpApiService.findIQCMsg00(code).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<IQCMsg00>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(IQCMsg00 iqcMsg00) {
                        listener.success(iqcMsg00);
                    }
                })
        ;
    }

    public void findSamplePlan(final IQCModel.SamplePlanListener listener){
        httpApiService.findSamplingPlan().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<IQCSamplePlan>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(IQCSamplePlan iqcSamplePlan) {
                        listener.success(iqcSamplePlan);
                    }
                })
        ;
    }

    public void findCust00( final IQCModel.Cust00Listener listener){
        httpApiService.findCust00().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<IQCCust00>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(IQCCust00 cust00) {
                        listener.success(cust00);
                    }
                })
        ;
    }

    public interface SamplePlanListener{
        void success(IQCSamplePlan iqcSamplePlan);

        void fail(Throwable e);
    }

    public interface Cust00Listener{
        void success(IQCCust00 iqcCust00);

        void fail(Throwable e);
    }

    public interface Msg00Listener{
        void success(IQCMsg00 iqcMsg00);

        void fail(Throwable e);
    }
}
